package com.buyi.easyhome.util

import android.content.Context
import android.text.TextUtils
import com.buyi.easyhome.R

object CommonUtils {

    fun getIPAddressForFTPService(context: Context?): String? {
        if (NetworkEnvironmentUtil.isWifiConnected(context!!)) {
            val wifiIp = NetworkEnvironmentUtil.getWifiIp(context)
            if (!TextUtils.isEmpty(wifiIp)) return wifiIp
        }
        val ips: ArrayList<String> = NetworkEnvironmentUtil.getLocalIpv4Addresses()
        if (ips.isNotEmpty()) return ips[0]
        return "127.0.0.1"
    }

    fun getResids(numbers: String): IntArray {
        val resids = IntArray(numbers.length)
        for (i in 0 until numbers.length) {
            resids[i] = getResid(numbers[i].toString())
        }
        if (numbers.length > 1) {
            return intArrayOf(resids[0], R.raw.tts_ten, resids[1])
        }
        return resids
    }

    fun getResid(number: String): Int {
        when (number) {
            "1" -> {
                return R.raw.tts_1
            }
            "2" -> {
                return R.raw.tts_2
            }
            "3" -> {
                return R.raw.tts_3
            }
            "4" -> {
                return R.raw.tts_4
            }
            "5" -> {
                return R.raw.tts_5
            }
            "6" -> {
                return R.raw.tts_6
            }
            "7" -> {
                return R.raw.tts_7
            }
            "8" -> {
                return R.raw.tts_8
            }
            "9" -> {
                return R.raw.tts_9
            }
            "0" -> {
                return R.raw.tts_0
            }
        }
        throw IllegalArgumentException("Invalid number")
    }

}